library(tidyverse)
## ── Attaching packages ───────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.2.1 ✓ purrr 0.3.3
## ✓ tibble 2.1.3 ✓ dplyr 0.8.3
## ✓ tidyr 1.0.0 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.4.0
## ── Conflicts ──────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ggmap)
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(lubridate)
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
library(gganimate)
raw = readr::read_csv("DL_FIRE_M6_94689/fire_nrt_M6_94689.csv")
## Parsed with column specification:
## cols(
## latitude = col_double(),
## longitude = col_double(),
## brightness = col_double(),
## scan = col_double(),
## track = col_double(),
## acq_date = col_date(format = ""),
## acq_time = col_character(),
## satellite = col_character(),
## instrument = col_character(),
## confidence = col_double(),
## version = col_character(),
## bright_t31 = col_double(),
## frp = col_double(),
## daynight = col_character()
## )
glimpse(raw)
## Observations: 101,639
## Variables: 14
## $ latitude <dbl> -35.493, -33.992, -33.991, -33.985, -33.983, -33.980, -33.…
## $ longitude <dbl> 149.639, 150.129, 150.118, 150.085, 150.074, 150.051, 150.…
## $ brightness <dbl> 379.8, 380.4, 406.0, 334.4, 335.3, 329.2, 330.7, 327.1, 34…
## $ scan <dbl> 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.1, 1.0, 1.0, 1.0, 1.0…
## $ track <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
## $ acq_date <date> 2019-12-01, 2019-12-01, 2019-12-01, 2019-12-01, 2019-12-0…
## $ acq_time <chr> "0000", "0000", "0000", "0000", "0000", "0000", "0000", "0…
## $ satellite <chr> "Terra", "Terra", "Terra", "Terra", "Terra", "Terra", "Ter…
## $ instrument <chr> "MODIS", "MODIS", "MODIS", "MODIS", "MODIS", "MODIS", "MOD…
## $ confidence <dbl> 94, 100, 100, 66, 67, 70, 75, 59, 94, 100, 86, 80, 51, 46,…
## $ version <chr> "6.0NRT", "6.0NRT", "6.0NRT", "6.0NRT", "6.0NRT", "6.0NRT"…
## $ bright_t31 <dbl> 288.9, 305.2, 315.7, 299.8, 299.1, 298.9, 299.0, 298.1, 29…
## $ frp <dbl> 156.0, 157.8, 300.1, 28.2, 30.0, 24.0, 26.1, 21.4, 55.2, 1…
## $ daynight <chr> "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D"…
raw$acq_time %>% unique %>% sample(size = 50) ## Four digits time stamp
## [1] "0700" "1305" "2345" "1635" "0545" "0455" "0640" "0605" "0450" "0015"
## [11] "1325" "0445" "0500" "1245" "0105" "2340" "1415" "0635" "0155" "1655"
## [21] "1650" "0540" "1730" "1350" "1420" "0440" "0020" "1615" "1155" "0530"
## [31] "0320" "1620" "1425" "1300" "0125" "1735" "0555" "0300" "1545" "1725"
## [41] "1335" "0315" "0505" "0355" "1750" "1610" "0430" "0405" "0225" "1755"
I am only selecting some variables of interest to me.
clean = raw %>%
dplyr::transmute(
latitude,
longitude,
brightness,
confidence,
bright_t31,
frp,
daynight,
my_time = paste0(acq_date, " ", acq_time) %>%
lubridate::ymd_hm(), ## Aftering pasting the hours and minites, we use lubridate to clean this
confidence,
conf_cat = cut(
confidence,
c(-1, 50, 101),
labels = c("low", "high")) %>% as.factor,
brightness,
bright_cat = cut(
brightness,
c(300, 350, 400, Inf),
labels = c("low", "med", "high")) %>% as.factor
)
glimpse(clean)
## Observations: 101,639
## Variables: 10
## $ latitude <dbl> -35.493, -33.992, -33.991, -33.985, -33.983, -33.980, -33.…
## $ longitude <dbl> 149.639, 150.129, 150.118, 150.085, 150.074, 150.051, 150.…
## $ brightness <dbl> 379.8, 380.4, 406.0, 334.4, 335.3, 329.2, 330.7, 327.1, 34…
## $ confidence <dbl> 94, 100, 100, 66, 67, 70, 75, 59, 94, 100, 86, 80, 51, 46,…
## $ bright_t31 <dbl> 288.9, 305.2, 315.7, 299.8, 299.1, 298.9, 299.0, 298.1, 29…
## $ frp <dbl> 156.0, 157.8, 300.1, 28.2, 30.0, 24.0, 26.1, 21.4, 55.2, 1…
## $ daynight <chr> "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D"…
## $ my_time <dttm> 2019-12-01, 2019-12-01, 2019-12-01, 2019-12-01, 2019-12-0…
## $ conf_cat <fct> high, high, high, high, high, high, high, high, high, high…
## $ bright_cat <fct> med, med, high, low, low, low, low, low, low, med, low, lo…
This code is not reproducible unless you have the correct Google Maps API.
nowra_map <- get_map("Nowra Hill, NSW", zoom = 10)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=Nowra%20Hill,%20NSW&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Nowra+Hill,+NSW&key=xxx
str(nowra_map)
## 'ggmap' chr [1:1280, 1:1280] "#BABAB6" "#D6D6CA" "#EAEADE" "#EAEAE2" ...
## - attr(*, "source")= chr "google"
## - attr(*, "maptype")= chr "terrain"
## - attr(*, "zoom")= num 10
## - attr(*, "bb")=Classes 'tbl_df', 'tbl' and 'data.frame': 1 obs. of 4 variables:
## ..$ ll.lat: num -35.3
## ..$ ll.lon: num 150
## ..$ ur.lat: num -34.6
## ..$ ur.lon: num 151
map_bounds = attr(nowra_map, "bb")
nowra_data = clean %>%
dplyr::filter(
latitude >= map_bounds$ll.lat,
latitude <= map_bounds$ur.lat,
longitude >= map_bounds$ll.lon,
longitude <= map_bounds$ur.lon)
nowra_data %>% glimpse
## Observations: 2,137
## Variables: 10
## $ latitude <dbl> -35.285, -35.284, -35.290, -35.286, -34.964, -34.963, -34.…
## $ longitude <dbl> 150.246, 150.235, 150.171, 150.209, 150.639, 150.627, 150.…
## $ brightness <dbl> 326.3, 335.0, 337.7, 314.1, 323.6, 311.1, 311.6, 319.1, 33…
## $ confidence <dbl> 43, 83, 100, 50, 100, 82, 83, 98, 76, 70, 63, 100, 100, 10…
## $ bright_t31 <dbl> 296.4, 295.3, 290.2, 288.5, 287.4, 285.9, 286.7, 287.0, 30…
## $ frp <dbl> 20.0, 31.8, 44.5, 14.1, 28.1, 15.1, 14.7, 22.3, 95.0, 7.3,…
## $ daynight <chr> "D", "D", "N", "N", "N", "N", "N", "N", "D", "N", "N", "N"…
## $ my_time <dttm> 2019-12-17 00:00:00, 2019-12-17 00:00:00, 2019-12-17 15:1…
## $ conf_cat <fct> low, high, high, low, high, high, high, high, high, high, …
## $ bright_cat <fct> low, low, low, low, low, low, low, low, low, low, low, med…
p1 = ggmap(nowra_map) +
geom_point(data = nowra_data,
aes(x = longitude,
y = latitude,
colour = brightness)) +
geom_point(x = 150.5934431,
y = -34.8432388,
colour = "blue", size = 2) + ## A location near my home
scale_colour_distiller(palette = "Reds", direction = 1) +
transition_states(my_time) +
labs(title = "Time: {closest_state}") +
shadow_trail(distance = 0.05, colour = "black", alpha = 1)
p2 = animate(p1, nframes = 100, fps = 3)
p2